//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Schedule.h"
using namespace Cephei::QL::Times;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/Period.h>
#undef HANDLE
#undef ABSTRACT
#define STRUCT
Cephei::QL::Times::CSchedule::CSchedule () 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phSchedule = NULL;
#endif
        _ppSchedule = new boost::shared_ptr<QuantLib::Schedule> (new QuantLib::Schedule ( ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::CSchedule::CSchedule (Cephei::Core::IVector<DateTime>^ dates, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ calendar, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ convention) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CCalendar^ _Ccalendar;
    try
    {
#ifdef HANDLE
        _phSchedule = NULL;
#endif
        dates->Lock();
        INativeVector<DateTime>^ _NCIdates = dates->getFeature (NativeFeature::Value);
        CDateTimeVector^ _NCdates = safe_cast<CDateTimeVector^>(_NCIdates);
        std::vector<QuantLib::Date>& _dates = static_cast<std::vector<QuantLib::Date>&> (_NCdates->GetReference ());
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>::IsSome::get (calendar))
        {
            _Ccalendar = safe_cast<CCalendar^> (calendar->Value);
            _Ccalendar->Lock();
        }
        QuantLib::Calendar& _calendar = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>::IsSome::get (calendar) ? static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()) : QuantLib::NullCalendar()); //1
        QuantLib::BusinessDayConvention _convention = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>::IsSome::get (convention) ? (QuantLib::BusinessDayConvention)convention->Value : QuantLib::BusinessDayConvention::Unadjusted); //10
        _ppSchedule = new boost::shared_ptr<QuantLib::Schedule> (new QuantLib::Schedule ( _dates,  _calendar,  _convention ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (dates != nullptr) dates->Unlock();    //not optional
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
    }
}
Cephei::QL::Times::CSchedule::CSchedule (DateTime effectiveDate, DateTime terminationDate, Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, QL::Times::BusinessDayConventionEnum terminationDateConvention, QL::Times::DateGeneration::RuleEnum rule, Boolean endOfMonth, Microsoft::FSharp::Core::FSharpOption<DateTime>^ firstDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ nextToLastDate) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CPeriod^ _Ctenor;
    CCalendar^ _Ccalendar;
    try
    {
#ifdef HANDLE
        _phSchedule = NULL;
#endif
        QuantLib::Date _effectiveDate = (QuantLib::Date)ValueHelper::Convert (effectiveDate); //d
        QuantLib::Date _terminationDate = (QuantLib::Date)ValueHelper::Convert (terminationDate); //d
        _Ctenor = safe_cast<CPeriod^> (tenor);
        _Ctenor->Lock();
        QuantLib::Period& _tenor = static_cast<QuantLib::Period&> (_Ctenor->GetReference ()); 
        _Ccalendar = safe_cast<CCalendar^> (calendar);
        _Ccalendar->Lock();
        QuantLib::Calendar& _calendar = static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()); 
        QuantLib::BusinessDayConvention _convention = (QuantLib::BusinessDayConvention)convention ;
        QuantLib::BusinessDayConvention _terminationDateConvention = (QuantLib::BusinessDayConvention)terminationDateConvention ;
        QuantLib::DateGeneration::Rule _rule = (QuantLib::DateGeneration::Rule)rule ;
        bool _endOfMonth = (bool)ValueHelper::Convert (endOfMonth); //d
        QuantLib::Date _firstDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (firstDate) ? (QuantLib::Date)ValueHelper::Convert (firstDate->Value) : QuantLib::Date()); //4
        QuantLib::Date _nextToLastDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (nextToLastDate) ? (QuantLib::Date)ValueHelper::Convert (nextToLastDate->Value) : QuantLib::Date()); //4
        _ppSchedule = new boost::shared_ptr<QuantLib::Schedule> (new QuantLib::Schedule ( _effectiveDate,  _terminationDate,  _tenor,  _calendar,  _convention,  _terminationDateConvention,  _rule,  _endOfMonth,  _firstDate,  _nextToLastDate ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ctenor != nullptr) _Ctenor->Unlock();
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
    }
}
Cephei::QL::Times::CSchedule::CSchedule (boost::shared_ptr<QuantLib::Schedule>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phSchedule = NULL;
#endif
	_ppSchedule = &childNative;
    
}
Cephei::QL::Times::CSchedule::CSchedule (QuantLib::Schedule& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phSchedule = NULL;
#endif
	_ppSchedule = new boost::shared_ptr<QuantLib::Schedule> (&childNative);
    
    _ScheduleOwner = owner;
    
}

Cephei::QL::Times::CSchedule::CSchedule (CSchedule^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phSchedule = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSchedule = new boost::shared_ptr<QuantLib::Schedule> (copy->GetShared());
        
    }
}
Cephei::QL::Times::CSchedule::CSchedule (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phSchedule = NULL;
#endif
	if (!t->IsSubclassOf(CSchedule::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::CSchedule::CSchedule (QuantLib::Handle<QuantLib::Schedule>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phSchedule = &childNative;
	_ppSchedule = &static_cast<boost::shared_ptr<QuantLib::Schedule>>(childNative.currentLink());
    
    _ScheduleOwner = owner;
}
Cephei::QL::Times::CSchedule::CSchedule (QuantLib::Handle<QuantLib::Schedule> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phSchedule = &childNative;
	_ppSchedule = &static_cast<boost::shared_ptr<QuantLib::Schedule>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Times::CSchedule::CSchedule (QuantLib::Schedule childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phSchedule = NULL;
#endif
	_ppSchedule = new boost::shared_ptr<QuantLib::Schedule> (new QuantLib::Schedule (childNative));
    
}
#endif

Cephei::QL::Times::CSchedule::~CSchedule ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppSchedule != NULL)
    {
	    delete _ppSchedule;
        _ppSchedule = NULL;
    }
}
Cephei::QL::Times::CSchedule::!CSchedule ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppSchedule != NULL)
    {
	    delete _ppSchedule;
    }
}
QuantLib::Schedule& Cephei::QL::Times::CSchedule::GetReference ()
{
    if (_ppSchedule == NULL) throw REFNEW NativeNullException ();
	return **_ppSchedule;
}
boost::shared_ptr<QuantLib::Schedule>& Cephei::QL::Times::CSchedule::GetShared ()
{
    if (_ppSchedule == NULL) throw REFNEW NativeNullException ();
	return *_ppSchedule;
}
QuantLib::Schedule* Cephei::QL::Times::CSchedule::GetPointer ()
{
    if (_ppSchedule == NULL) throw REFNEW NativeNullException ();
	return &**_ppSchedule;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Schedule>& Cephei::QL::Times::CSchedule::GetHandle ()
{
	if (_phSchedule == NULL)
	{
		_phSchedule = new Handle<QuantLib::Schedule> (*_ppSchedule);
	}
	return *_phSchedule;
}
#endif
bool Cephei::QL::Times::CSchedule::HasNative () 
{
	return (_ppSchedule != NULL);
}

DateTime Cephei::QL::Times::CSchedule::At (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSchedule)->at ( _i );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::BusinessDayConventionEnum Cephei::QL::Times::CSchedule::BusinessDayConvention::get ()
{
    try
    {
    	QuantLib::BusinessDayConvention _rv = (QuantLib::BusinessDayConvention)(*_ppSchedule)->businessDayConvention ( );   
        QL::Times::BusinessDayConventionEnum _nrv = (QL::Times::BusinessDayConventionEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ICalendar^ Cephei::QL::Times::CSchedule::Calendar::get ()
{
    try
    {
    	QuantLib::Calendar& _rv = (QuantLib::Calendar&)(*_ppSchedule)->calendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = REFNEW Cephei::QL::Times::CCalendar (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Times::CSchedule::Date (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSchedule)->date ( _i );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<DateTime>^ Cephei::QL::Times::CSchedule::Dates::get ()
{
    try
    {
    	std::vector<QuantLib::Date>& _rv = (std::vector<QuantLib::Date>&)(*_ppSchedule)->dates ( );   
        Cephei::Core::IVector<DateTime>^ _nrv = REFNEW CoVector<DateTime> (REFNEW CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Times::CSchedule::Empty::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppSchedule)->empty ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Times::CSchedule::EndDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSchedule)->endDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Times::CSchedule::EndOfMonth::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppSchedule)->endOfMonth ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Times::CSchedule::IsRegular (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	bool _rv = (bool)(*_ppSchedule)->isRegular ( _i );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Times::CSchedule::NextDate (DateTime refDate)
{
    try
    {
        QuantLib::Date _refDate = (QuantLib::Date)ValueHelper::Convert (refDate); //a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSchedule)->nextDate ( _refDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Times::CSchedule::PreviousDate (DateTime refDate)
{
    try
    {
        QuantLib::Date _refDate = (QuantLib::Date)ValueHelper::Convert (refDate); //a
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSchedule)->previousDate ( _refDate );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::DateGeneration::RuleEnum Cephei::QL::Times::CSchedule::Rule::get ()
{
    try
    {
    	QuantLib::DateGeneration::Rule _rv = (QuantLib::DateGeneration::Rule)(*_ppSchedule)->rule ( );   
        QL::Times::DateGeneration::RuleEnum _nrv = (QL::Times::DateGeneration::RuleEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt64 Cephei::QL::Times::CSchedule::Size::get ()
{
    try
    {
    	QuantLib::Size _rv = (QuantLib::Size)(*_ppSchedule)->size ( );   
        UInt64 _nrv = _rv; //c1
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Times::CSchedule::StartDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSchedule)->startDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IPeriod^ Cephei::QL::Times::CSchedule::Tenor::get ()
{
    try
    {
    	QuantLib::Period& _rv = (QuantLib::Period&)(*_ppSchedule)->tenor ( );   
        Cephei::QL::Times::CPeriod^ _nrv = REFNEW Cephei::QL::Times::CPeriod (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::BusinessDayConventionEnum Cephei::QL::Times::CSchedule::TerminationDateBusinessDayConvention::get ()
{
    try
    {
    	QuantLib::BusinessDayConvention _rv = (QuantLib::BusinessDayConvention)(*_ppSchedule)->terminationDateBusinessDayConvention ( );   
        QL::Times::BusinessDayConventionEnum _nrv = (QL::Times::BusinessDayConventionEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Times::CSchedule::Until (DateTime truncationDate)
{
    try
    {
        QuantLib::Date _truncationDate = (QuantLib::Date)ValueHelper::Convert (truncationDate); //a
    	QuantLib::Schedule _rv = (QuantLib::Schedule)(*_ppSchedule)->until ( _truncationDate );   
        Cephei::QL::Times::CSchedule^ _nrv = REFNEW Cephei::QL::Times::CSchedule (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::ISchedule^ Cephei::QL::Times::CSchedule_Factory::Create ()
{
    return REFNEW CSchedule ();
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Times::CSchedule_Factory::Create (Cephei::Core::IVector<DateTime>^ dates, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ICalendar^>^ calendar, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ convention)
{
    return REFNEW CSchedule ( dates,  calendar,  convention);
}
Cephei::QL::Times::ISchedule^ Cephei::QL::Times::CSchedule_Factory::Create (DateTime effectiveDate, DateTime terminationDate, Cephei::QL::Times::IPeriod^ tenor, Cephei::QL::Times::ICalendar^ calendar, QL::Times::BusinessDayConventionEnum convention, QL::Times::BusinessDayConventionEnum terminationDateConvention, QL::Times::DateGeneration::RuleEnum rule, Boolean endOfMonth, Microsoft::FSharp::Core::FSharpOption<DateTime>^ firstDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ nextToLastDate)
{
    return REFNEW CSchedule ( effectiveDate,  terminationDate,  tenor,  calendar,  convention,  terminationDateConvention,  rule,  endOfMonth,  firstDate,  nextToLastDate);
}
